home *** CD-ROM | disk | FTP | other *** search
Text File | 1985-05-31 | 1.8 KB | 77 lines | [TEXT/TRUE] |
- ! Library of mathematical functions
- ! Copyright (c) 1985 by True BASIC, Inc.
-
- EXTERNAL
-
- DEF logbase(x,b) ! Log to base b
- IF b<=0 or b=1 then
- CAUSE EXCEPTION -3000, "Argument not in range"
- ELSE
- LET logbase = log(x)/log(b)
- END IF
- END DEF
-
- DEF erf(x) ! Error function
- DECLARE DEF norm1
- LET erf = 2*norm1(sqr(2)*x)
- END DEF
-
- DEF normal(a,b) ! Area under normal curve
- DECLARE DEF norm1
- IF a*b<0 then
- LET normal = norm1(a) + norm1(b)
- ELSE
- LET normal = abs(norm1(a) - norm1(b))
- END IF
- END DEF
-
- DEF norm1(x) ! Normal from 0 to x
- LET x1 = abs(x)
- IF x1>5.1 then
- LET norm1 = .5
- EXIT DEF
- END IF
- LET u = x1*x1/2
- LET c = 1/sqr(2*pi)
- LET term, sum = x1
- FOR i = 1 to 45
- LET term = -term * u/i
- LET sum = sum + term/(2*i+1)
- NEXT i
- LET norm1 = c*sum
- END DEF
-
- DEF factrl(n) ! Factorial
- IF n<0 or n<>int(n) then CAUSE EXCEPTION -3000, "Argument not in range"
- LET f = 1
- FOR i = 1 to n
- LET f = f*i
- NEXT i
- LET factrl = f
- END DEF
-
- DEF binom(n,j) ! Binomial coefficient
- IF n<0 or n<>int(n) or j<0 or j<>int(j) then CAUSE EXCEPTION -3000, "Argument not in range"
- IF j>n then
- LET binom = 0
- EXIT DEF
- END IF
- LET j1 = min(j,n-j)
- LET b = 1
- FOR k = 1 to j1
- LET b = b*(n-k+1)/k
- NEXT k
- LET binom = b
- END DEF
-
- DEF binompr(n,j,p) ! Binomial distribution
- DECLARE DEF binom
- IF p<0 or p>1 then CAUSE EXCEPTION -3000, "Argument not in range"
- LET binompr = binom(n,j) * p^j * (1-p)^(n-j)
- END DEF
-
- DEF poisson(m,j) ! Poisson distribution
- DECLARE DEF factrl
- LET poisson = exp(-m) * m^j / factrl(j)
- END DEF
-